import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class TCPClient {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(8888);

        Socket socket = serverSocket.accept(); // 获取客户端对象

        InputStream inputStream = socket.getInputStream();
        byte[] message = new byte[1024];
        int len = 0;
        OutputStream outputStream = socket.getOutputStream();

        while ((len = inputStream.read(message)) != 0) {
            String str = new String(message, 0, len);
            System.out.println(str);
            outputStream.write("I have received your messages".getBytes());
        }



    }
}
